package example;

public class TestThread0607 {
	int j;

	public TestThread0607(int j) {
		this.j = j;
	}

	private synchronized void inc() {
		j++;
		System.out.println(j + "--Inc--" + Thread.currentThread().getName());
	}

	private synchronized void dec() {
		j--;
		System.out.println(j + "--Dec--" + Thread.currentThread().getName());
	}

	public void run() {
		(new Dec()).start();
		new Thread(new Inc()).start();
		(new Dec()).start();
		new Thread(new Inc()).start();
	}

	class Dec extends Thread {
		public void run() {
			for (int i = 0; i < 100; i++) {
				dec();
			}
		}
	}

	class Inc implements Runnable {
		public void run() {
			for (int i = 0; i < 100; i++) {
				inc();
			}
		}
	}

	public static void main(String[] args) {
		(new TestThread0607(5)).run();
	}
}